package player.ui.dialog;

import java.text.Collator;
import java.util.Comparator;

import player.mplayer.MediaInfo;

public class MediaInfoComparator implements Comparator {

	public static int stype_FileName=123;
	public static int stype_FileLength=124;
	public static int stype_PlayTime=125;
	public static int stype_FileType=126;
	int sortType=stype_FileName;
	Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
	public MediaInfoComparator(int type){
		this.sortType=type;
	}
	public int compare(Object o1, Object o2) {
		MediaInfo m1=(MediaInfo) o1;
		MediaInfo m2=(MediaInfo) o2;
		int n=0;
		if(sortType==stype_FileName){
			n=cmp.compare(m1.fileName, m2.fileName);
		}else if(sortType==stype_FileLength){
			if(m1.fileSize>m2.fileSize){
				n=1;
			}
		}else if(sortType==stype_PlayTime){
			if(m1.length>m2.length){
				n=1;
			}
		}else if(sortType==stype_FileType){
			n=cmp.compare(getExentName(m1.fileName), getExentName(m2.fileName));
		}
		return n;
	}
	
	
	String getExentName(String fn){
		String en="";
		int index=fn.lastIndexOf(".");
		if(index>0){
			en=fn.substring(index+1);
		}
		return en;
			
	}
	
	

}
